/*
 * @Descripttion:权限控制公共方法
 * @version:
 * @Author: zhangfan
 * @email: 2207044692@qq.com
 * @Date: 2020-08-28 15:07:01
 * @LastEditors: zhangfan
 * @LastEditTime: 2020-08-28 16:08:35
 */
import store from '../store'

function accessControl(val) {
  let index = changeMainListDate(store.state.menuListTotal).findIndex(
    (item) => {
      if (val === item.url) {
        return true
      } else {
        return false
      }
    }
  )
  return index
}

function changeMainListDate(tree = []) {
  let arr = []
  if (!!tree && tree.length !== 0) {
    tree.forEach((item) => {
      let obj = {}
      obj.name = item.name
      obj.url = item.url
      if (item.child) {
        item.child.forEach((item) => {
          let objchild = {}
          objchild.name = item.name
          objchild.url = item.url
          arr.push(objchild)
        })
      }
      arr.push(obj)
    })
  }
  return arr
}

export default accessControl
